package com.wayne.blog.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wayne.blog.common.Ret;
import com.wayne.blog.entity.Tag;
import com.wayne.blog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/tags")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping("/list")
    public Ret<Page<Tag>> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size) {
        Page<Tag> page = tagService.page(new Page<>(current, size));
        return Ret.success(page);
    }

    @PostMapping
    public Ret<?> add(@RequestBody Tag tag) {
        tagService.save(tag);
        return Ret.success();
    }

    @PutMapping("/{id}")
    public Ret<?> update(@PathVariable Long id, @RequestBody Tag tag) {
        tag.setId(id);
        tagService.updateById(tag);
        return Ret.success();
    }

    @DeleteMapping("/{id}")
    public Ret<?> delete(@PathVariable Long id) {
        tagService.removeById(id);
        return Ret.success();
    }
} 